<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>FreeMarker宏macro</title>
</head>
<body style="margin-left: 50px;">
    <h2>1、macro：宏指令</h2>
    <ul>
        <li><strong>例子1：无参数的macro</strong></li>
        <div>
            <#macro test1>
                <font color="red">无参数的macro</font>
            </#macro>
            <@test1 />
        </div>
        <li><strong>例子2：有参数的macro</strong></li>
        <div>
            <#macro test2 param1 param2>
                <font color="red">有参数的macro，param1=${param1}，param2=${param2}</font>
            </#macro>
            <@test2 param1="Java" param2="Python" />
        </div>
        <li><strong>例子3：有默认值参数的macro</strong></li>
        <div>
            <#macro test3 param1 param2="Python">
                <font color="red">有参数的macro，param1=${param1}，param2=${param2}</font>
            </#macro>
            <@test3 param1="Java" />
        </div>
        <li><strong>例子4：有不定个数参数的macro</strong></li>
        <div>
            <#macro test4 param1 param2="Python" paramExt...>
                <font color="red">有参数的macro，param1=${param1}，param2=${param2}</font><br/>
                <font color="red">${paramExt['param3']}</font><br/>
                <font color="red">${paramExt['param4']}</font>
            </#macro>
            <@test4 param1="Java" param2="Python" param3="JavaScript" param4="NodeJs"/>
        </div>
    </ul>

    <h2>2、nested</h2>
    <#macro test5 param1="Java">
        param1=${param1}<br/>
        <!-- nested定义的参数将会传递给调用方 -->
        <#nested param1 "我的nested参数"><br/>
    </#macro>
    <ul>
        <li><strong>调用</strong></li>
        <div>
            <!-- 声明loopVar1和loopVar2两个变量来引用nested传递过来的参数 -->
            <@test5 param1="javascript" ; loopVar1, loopVar2>
                <font color="red">hello ${loopVar1}, ${loopVar2}</font><br/>
            </@test5>

            <@test5 param1="python" ; loopVar1>
                hello ${loopVar1}<br/>
            </@test5>
        </div>
    </ul>
</body>
</html>